import routesData from './routes.json'

// 获取动态路由配置
export async function getDynamicRoutes() {
  try {
    return routesData.routes
  } catch (e) {
    console.error('获取动态路由失败', e)
    return []
  }
}

// 验证路由权限
export async function checkRoutePermission(routePath) {
  try {
    const route = routesData.routes.find(r => r.path === routePath)
    if (!route) return false
    
    const userRoles = uni.getStorageSync('userRoles') || []
    return route.permissions.some(perm => userRoles.includes(perm))
  } catch (e) {
    console.error('验证路由权限失败', e)
    return false
  }
}